@model Post
@{
    var isNew = string.IsNullOrEmpty(Model.Title);
    ViewData[Constants.Title] = "Edit " + (Model.Title ?? "new post");
    var host = Context.Request.Host.ToString();
    var allCats = ViewData[Constants.AllCats] as List<string> ?? new List<string>();
    var allTags = ViewData[Constants.AllTags] as List<string> ?? new List<string>();
}

@section Head {
    <link rel="stylesheet" href="~/css/admin.scss" />
}

    <form method="post" id="edit" class="container" asp-controller="Blog" asp-action="UpdatePost">
        <div asp-validation-summary="All"></div>
        <input type="hidden" asp-for="@Model.ID" />

        <label asp-for="@Model.Title" class="label">Title</label>
        <input asp-for="@Model.Title" required placeholder="Title of blog post" aria-describedby="desc_title" />
        <span class="desc" id="desc_title">The title as it appears on the website</span>
        <br />

        <label asp-for="@Model.Slug" class="label">Slug</label>
        <input asp-for="@Model.Slug" placeholder="The URL name" aria-describedby="desc_slug" />
        <span class="desc" id="desc_slug">The part of the URL that identifies this blog post</span>
        <br />

        <label for="categories" class="label">Categories</label>
        <input type="text" name="selectcat" id="selectcat" aria-describedby="desc_categories" list="catlist" placeholder="@string.Join(", ", Model.Categories)"  />
        <input type="text" name="categories" id="categories" value="@string.Join(", ", Model.Categories)" hidden />
        <span class="desc" id="desc_categories">Select, or build a comma separated list of keywords - to remove double the keyword</span>
        <datalist id="catlist">
            @foreach (var cat in allCats)
            {
                <option value="@cat"/>
            }
            </datalist>
        <br />

        <label for="tags" class="label">Tags</label>
        <input type="text" name="selecttag" id="selecttag" aria-describedby="desc_tags" list="taglist" placeholder="@string.Join(", ", Model.Tags)"  />
        <input type="text" name="tags" id="tags" value="@string.Join(", ", Model.Tags)" hidden />
        <span class="desc" id="desc_tags">Select, or build a comma separated list of keywords - to remove double the keyword</span>
        <datalist id="taglist">
            @foreach (var tag in allTags)
            {
                <option value="@tag"/>
            }
            </datalist>
        <br />

        <label asp-for="@Model.Excerpt" class="label">Excerpt</label>
        <textarea asp-for="@Model.Excerpt" rows="3" placeholder="Short description of blog post" aria-describedby="desc_excerpt">@Model.Excerpt</textarea>
        <span class="desc" id="desc_excerpt">A brief description of the content of the post</span>
        <br />

        <textarea asp-for="@Model.Content" rows="20" aria-label="Content">@Model.Content</textarea>
        <br />

        <input type="submit" value="Save" title="Save the post" />

        <input asp-for="@Model.IsPublished" />
        <label asp-for="@Model.IsPublished">Is published</label>

        @if (!isNew)
        {
            <input type="submit" value="Delete..." class="delete" title="Delete the post..." asp-action="DeletePost" asp-route-id="@Model.ID" />
        }
    </form>

@section Scripts {
    <script src="//@host/lib/tinymce/tinymce.min.js"></script> @*with enabled CDN tinymce is not able to find some files*@
    <script src="~/js/admin.js" async></script>
}
